<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
    

    

    



    <meta charset="utf-8">
    
    
    
    
    <title>Vue.js的生命周期 | 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~ | It&#39;s founded on March 9, 2019 and the open source address for the blog notes https://github.com/YUbuntu0109/YUbuntu0109.github.io</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="Vue">
    <meta name="description" content="学习笔记 : 详解Vue.js的生命周期Vue实例的生命周期函数从Vue实例创建,运行,到销毁期间,总是伴随着各种各样的事件,这些事件统称为生命周期,至于生命周期钩子只不过是生命周期事件的别名而已. 其生命周期图如下所示 :">
<meta name="keywords" content="Vue">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue.js的生命周期">
<meta property="og:url" content="https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/index.html">
<meta property="og:site_name" content="欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~">
<meta property="og:description" content="学习笔记 : 详解Vue.js的生命周期Vue实例的生命周期函数从Vue实例创建,运行,到销毁期间,总是伴随着各种各样的事件,这些事件统称为生命周期,至于生命周期钩子只不过是生命周期事件的别名而已. 其生命周期图如下所示 :">
<meta property="og:locale" content="en">
<meta property="og:image" content="https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/Vue-lifecycle.png">
<meta property="og:image" content="https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/vue-lifecycle-created+mounted.PNG">
<meta property="og:image" content="https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/vue-lifecycle-updated.PNG">
<meta property="og:image" content="https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/vue-lifecycle-destroyed.PNG">
<meta property="og:updated_time" content="2020-03-31T12:36:02.581Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Vue.js的生命周期">
<meta name="twitter:description" content="学习笔记 : 详解Vue.js的生命周期Vue实例的生命周期函数从Vue实例创建,运行,到销毁期间,总是伴随着各种各样的事件,这些事件统称为生命周期,至于生命周期钩子只不过是生命周期事件的别名而已. 其生命周期图如下所示 :">
<meta name="twitter:image" content="https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/Vue-lifecycle.png">
    
        <link rel="alternate" type="application/atom+xml" title="欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~" href="/atom.xml">
    
    <link rel="shortcut icon" href="/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@latest/css/style.css">
    <script>window.lazyScripts=[]</script>

    <!-- custom head -->
    

</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/img/brand.jpg)">
      <div class="brand">
        <a href="/" class="avatar waves-effect waves-circle waves-light">
          <img src="/img/my-portrait.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">黄宇辉</h5>
          <a href="mailto:3083968068@qq.com" title="3083968068@qq.com" class="mail">3083968068@qq.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/"  >
                <i class="icon icon-lg icon-home"></i>
                Homepage
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                Archives
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                Tags
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                Categories
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/YUbuntu0109" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://space.bilibili.com/364361791" target="_blank" >
                <i class="icon icon-lg icon-link"></i>
                Bilibili
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">Vue.js的生命周期</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="Search">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
        <!-- add the background music on Mar 11,2019
        <div>
            <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=280 height=52 src="//music.163.com/outchain/player?type=2&id=438801642&auto=1&height=32"></iframe>
        </div>
        -->
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">Vue.js的生命周期</h1>
        <h5 class="subtitle">
            
                <time datetime="2019-07-20T21:56:19.000Z" itemprop="datePublished" class="page-time">
  2019-07-20
</time>


            
        </h5>
    </div>

    


</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap post-toc-shrink" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#学习笔记-详解Vue-js的生命周期"><span class="post-toc-number">1.</span> <span class="post-toc-text">学习笔记 : 详解Vue.js的生命周期</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#Vue实例的生命周期函数"><span class="post-toc-number">1.1.</span> <span class="post-toc-text">Vue实例的生命周期函数</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#初始阶段"><span class="post-toc-number">1.1.1.</span> <span class="post-toc-text">初始阶段</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#运行阶段"><span class="post-toc-number">1.1.2.</span> <span class="post-toc-text">运行阶段</span></a></li><li class="post-toc-item post-toc-level-4"><a class="post-toc-link" href="#销毁阶段"><span class="post-toc-number">1.1.3.</span> <span class="post-toc-text">销毁阶段</span></a></li></ol></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#生命周期函数程序示例"><span class="post-toc-number">1.2.</span> <span class="post-toc-text">生命周期函数程序示例</span></a></li></ol></li></ol>
        </nav>
    </aside>


<article id="post-Vue-js的生命周期"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">Vue.js的生命周期</h1>
        <div class="post-meta">
            <time class="post-time" title="2019-07-20 21:56:19" datetime="2019-07-20T21:56:19.000Z"  itemprop="datePublished">2019-07-20</time>

            


            

        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h2 id="学习笔记-详解Vue-js的生命周期"><a href="#学习笔记-详解Vue-js的生命周期" class="headerlink" title="学习笔记 : 详解Vue.js的生命周期"></a>学习笔记 : 详解Vue.js的生命周期</h2><h3 id="Vue实例的生命周期函数"><a href="#Vue实例的生命周期函数" class="headerlink" title="Vue实例的生命周期函数"></a>Vue实例的生命周期函数</h3><p><em>从Vue实例创建,运行,到销毁期间,总是伴随着各种各样的事件,这些事件统称为生命周期,至于生命周期钩子只不过是生命周期事件的别名而已. 其生命周期图如下所示 :</em></p>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/2019/07/20/Vue-js的生命周期/Vue-lifecycle.png" alt title>
                </div>
                <div class="image-caption"></div>
            </figure>
<h4 id="初始阶段"><a href="#初始阶段" class="headerlink" title="初始阶段"></a>初始阶段</h4><table>
<thead>
<tr>
<th style="text-align:center">钩子函数</th>
<th style="text-align:center">描述</th>
<th style="text-align:center">数据</th>
<th style="text-align:center">真实DOM</th>
<th style="text-align:center">项目中的应用</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">beforeCreate</td>
<td style="text-align:center">表示组件创建前的准备工作,为事件的发布订阅和生命周期的开始做初始化</td>
<td style="text-align:center">无</td>
<td style="text-align:center">无</td>
<td style="text-align:center">项目中一般不使用</td>
</tr>
<tr>
<td style="text-align:center">created</td>
<td style="text-align:center">表示组件创建结束</td>
<td style="text-align:center">有</td>
<td style="text-align:center">无</td>
<td style="text-align:center">异步数据请求,然后可以进行一次默认数据的修改</td>
</tr>
<tr>
<td style="text-align:center">beforeMount</td>
<td style="text-align:center">表示组件装载前的准备工作(VDOM)</td>
<td style="text-align:center">有</td>
<td style="text-align:center">无</td>
<td style="text-align:center">数据请求,它也可以进行一次数据修改</td>
</tr>
<tr>
<td style="text-align:center">mounted</td>
<td style="text-align:center">组件挂载结束,真实DOM渲染完成</td>
<td style="text-align:center">有</td>
<td style="text-align:center">有</td>
<td style="text-align:center">DOM操作,第三方库的实例化</td>
</tr>
</tbody>
</table>
<ul>
<li><em><code>beforeCreate</code> : 在实例初始化之后,数据观测(data observer)和event/watcher事件配置之前被调用</em></li>
<li><em><code>created</code> : 实例已经创建完成之后被调用. 在这一步,实例已完成以下的配置 : 数据观测(data observer)属性初始化和方法的运算,watch/event事件回调. 然而挂载阶段还没开始,<code>$el</code>属性目前不可见</em></li>
<li><em><code>beforeMount</code> : 在挂载开始之前被调用,相关的render函数首次被调用</em></li>
<li><em><code>mounted</code> : <code>el</code>被新创建的<code>vm.$el</code>替换，并挂载到实例上去之后调用该钩子. 如果root实例挂载了一个文档内元素,当mounted被调用时vm.$el也在文档内</em></li>
</ul>
<h4 id="运行阶段"><a href="#运行阶段" class="headerlink" title="运行阶段"></a>运行阶段</h4><table>
<thead>
<tr>
<th style="text-align:center">钩子函数</th>
<th style="text-align:center">描述</th>
<th style="text-align:center">数据</th>
<th style="text-align:center">真实DOM</th>
<th style="text-align:center">项目中的应用</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">beforeUpdate</td>
<td style="text-align:center">数据更新前的准备工作,数据修改才会执行</td>
<td style="text-align:center">有(修改后的数据)</td>
<td style="text-align:center">有</td>
<td style="text-align:center">生成新的VDOM,然后通过diff算法进行两次VDOM对比,没有太多的操作意义</td>
</tr>
<tr>
<td style="text-align:center">updated</td>
<td style="text-align:center">数据更新结束,通过render函数渲染真实DOM</td>
<td style="text-align:center">有</td>
<td style="text-align:center">有(重新渲染后的真实DOM)</td>
<td style="text-align:center">可以进行异步数据请求得到的DOM渲染的第三方库实例化</td>
</tr>
</tbody>
</table>
<ul>
<li><em><code>beforeUpdate</code> : 数据更新时调用,发生在虚拟DOM重新渲染和打补丁之前. 你可以在这个钩子中进一步地更改状态,这不会触发附加的重渲染过程</em></li>
<li><em><code>updated</code> : 由于数据更改导致的虚拟DOM重新渲染和打补丁,在这之后会调用该钩子. 当这个钩子被调用时,组件DOM已经更新,所以你现在可以执行依赖于DOM的操作</em></li>
</ul>
<h4 id="销毁阶段"><a href="#销毁阶段" class="headerlink" title="销毁阶段"></a>销毁阶段</h4><table>
<thead>
<tr>
<th style="text-align:center">钩子函数</th>
<th style="text-align:center">描述</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">beforeDestroy</td>
<td style="text-align:center">组件即将销毁,准备调用<code>$destroy()</code>方法</td>
</tr>
<tr>
<td style="text-align:center">destroyed</td>
<td style="text-align:center">组件销毁结束</td>
</tr>
</tbody>
</table>
<ul>
<li><em><code>beforeDestroy</code> : 实例销毁之前调用. 在这一步,实例仍然完全可用</em></li>
<li><em><code>destroyed</code> : Vue实例销毁后调用. 调用后,Vue实例指示的所有东西都会解绑定,所有的事件监听器会被移除,所有的子实例也会被销毁</em></li>
</ul>
<h3 id="生命周期函数程序示例"><a href="#生命周期函数程序示例" class="headerlink" title="生命周期函数程序示例"></a>生命周期函数程序示例</h3><p><em>可通过下面这个简单实例来观察这些生命周期函数执行的时机哟 ~</em><br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="meta-keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"resources/vue.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">title</span>&gt;</span>the life cycle of Vue<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">h2</span>&gt;</span>&#123;&#123;title&#125;&#125;<span class="tag">&lt;/<span class="name">h2</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">"randomTitle()"</span>&gt;</span>Change title<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">"destoryVm()"</span>&gt;</span>destory VM<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="actionscript">			<span class="keyword">var</span> vm = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="actionscript">				el: <span class="string">'#app'</span>,</span></span><br><span class="line">				data() &#123;</span><br><span class="line"><span class="actionscript">					<span class="keyword">return</span> &#123;</span></span><br><span class="line"><span class="actionscript">						title: <span class="string">'Hi Vue !'</span></span></span><br><span class="line">					&#125;</span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//methods将被混入到Vue实例中.可以直接通过VM实例访问这些方法,或者在指令表达式中使用.</span></span></span><br><span class="line"><span class="actionscript">				<span class="comment">//方法中的this自动绑定为Vue实例.</span></span></span><br><span class="line">				methods: &#123;</span><br><span class="line"><span class="actionscript">					randomTitle: <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="actionscript">						<span class="comment">//floor:returns the largest integer less than or equal to a number. </span></span></span><br><span class="line"><span class="javascript">						<span class="keyword">this</span>.title = <span class="string">'Hi '</span> + [<span class="string">'HTML'</span>, <span class="string">'CSS'</span>, <span class="string">'JS'</span>][<span class="built_in">Math</span>.floor(<span class="built_in">Math</span>.random() * <span class="number">2.99</span>)]</span></span><br><span class="line">					&#125;,</span><br><span class="line"><span class="actionscript">					destoryVm: <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>&#123;</span></span><br><span class="line"><span class="actionscript">						<span class="keyword">this</span>.$destroy()</span></span><br><span class="line">					&#125;</span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//实例初始化后,数据观测和事件绑定之前</span></span></span><br><span class="line">				beforeCreate() &#123;</span><br><span class="line"><span class="actionscript">					<span class="comment">//注:此时data和methods还未被初始化哟</span></span></span><br><span class="line"><span class="javascript">					<span class="built_in">console</span>.log(<span class="string">'before create'</span>)</span></span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//实例初始化完成,挂载尚未开始时 </span></span></span><br><span class="line">				created() &#123;</span><br><span class="line"><span class="actionscript">					<span class="comment">//注:此时data与methods已被初始化了哟</span></span></span><br><span class="line"><span class="javascript">					<span class="built_in">console</span>.log(<span class="string">'created'</span>)</span></span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//挂载之前,render函数首先被调用时</span></span></span><br><span class="line">				beforeMount() &#123;</span><br><span class="line"><span class="actionscript">					<span class="comment">//注:此时模板已在内存中编译完成,但尚未把模板渲染到页面中</span></span></span><br><span class="line"><span class="javascript">					<span class="built_in">console</span>.log(<span class="string">'before mount'</span>)</span></span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//在实例挂载到DOM节点之后</span></span></span><br><span class="line">				mounted() &#123;</span><br><span class="line"><span class="actionscript">					<span class="comment">//注:此时内存中的模板已真实挂载到页面中,继而完成页面的渲染</span></span></span><br><span class="line"><span class="javascript">					<span class="built_in">console</span>.log(<span class="string">'mounted'</span>)</span></span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//数据更新时,在虚拟DOM状态变化之前</span></span></span><br><span class="line">				beforeUpdate() &#123;</span><br><span class="line"><span class="actionscript">					<span class="comment">//注:数据被修改时则触发该事件,但此时页面上的数据并未更新哟</span></span></span><br><span class="line"><span class="javascript">					<span class="built_in">console</span>.log(<span class="string">'before update'</span>)</span></span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//虚拟DOM被重新渲染之后</span></span></span><br><span class="line">				updated() &#123;</span><br><span class="line"><span class="actionscript">					<span class="comment">//注:此时页面中的数据已经与data保持同步了哟</span></span></span><br><span class="line"><span class="javascript">					<span class="built_in">console</span>.log(<span class="string">'updated'</span>)</span></span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//实例销毁之前,此时实例依然可用</span></span></span><br><span class="line">				beforeDestroy() &#123;</span><br><span class="line"><span class="javascript">					<span class="built_in">console</span>.log(<span class="string">'before destory'</span>)</span></span><br><span class="line">				&#125;,</span><br><span class="line"><span class="actionscript">				<span class="comment">//实例销毁后,此时Vue实例及其子实例将完全解绑</span></span></span><br><span class="line">				destroyed() &#123;</span><br><span class="line"><span class="javascript">					<span class="built_in">console</span>.log(<span class="string">'destoryed'</span>)</span></span><br><span class="line">				&#125;</span><br><span class="line">			&#125;);</span><br><span class="line">		<span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<ol>
<li><em>刚打开页面,既Vue示例刚被创建并挂载到DOM上时,调用的钩子函数如下图所示 :</em></li>
</ol>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/2019/07/20/Vue-js的生命周期/vue-lifecycle-created+mounted.PNG" alt title>
                </div>
                <div class="image-caption"></div>
            </figure>
<ol start="2">
<li><em>点击<code>change title</code>按钮来改变标题数据,继而会触发视图更新,调用的钩子函数如下图所示 :</em></li>
</ol>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/2019/07/20/Vue-js的生命周期/vue-lifecycle-updated.PNG" alt title>
                </div>
                <div class="image-caption"></div>
            </figure>
<ol start="3">
<li><em>点击<code>destroy VM</code>按钮来销毁Vue实例,调用的钩子函数如下图所示 :</em></li>
</ol>
<figure class="image-bubble">
                <div class="img-lightbox">
                    <div class="overlay"></div>
                    <img src="/2019/07/20/Vue-js的生命周期/vue-lifecycle-destroyed.PNG" alt title>
                </div>
                <div class="image-caption"></div>
            </figure>
<ol start="4">
<li><em>之后,尝试多次点击<code>chang title</code>按钮,发现视图不再响应数据的变化,继而证明此时节点上绑定的Vue实例已被销毁 !</em></li>
</ol>

        </div>

        <blockquote class="post-copyright">
    
    <div class="content">
        
<span class="post-time">
    Last updated: <time datetime="2020-03-31T12:36:02.581Z" itemprop="dateUpdated">2020-03-31 12:36:02</time>
</span><br>


        
    </div>
    
    <footer>
        <a href="https://yubuntu0109.github.io">
            <img src="/img/my-portrait.jpg" alt="黄宇辉">
            黄宇辉
        </a>
    </footer>
</blockquote>

        
<div class="page-reward">
    <a id="rewardBtn" href="javascript:;" class="page-reward-btn waves-effect waves-circle waves-light">赏</a>
</div>



        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Vue/">Vue</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/&title=《Vue.js的生命周期》 — 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~&pic=https://yubuntu0109.github.io/img/my-portrait.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/&title=《Vue.js的生命周期》 — 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~&source=My Personal Website For Blog" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《Vue.js的生命周期》 — 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~&url=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/&via=https://yubuntu0109.github.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/2019/07/21/Vue-js的语法/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">Vue.js的语法</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/2019/07/19/Hi-Vue/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">Hi Vue ~</h4>
      </a>
    </div>
  
</nav>



    




















</article>

<div id="reward" class="page-modal reward-lay">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <h3 class="reward-title">
        <i class="icon icon-quote-left"></i>
        thanks ~
        <i class="icon icon-quote-right"></i>
    </h3>
    <div class="reward-content">
        
        <div class="reward-code">
            <img id="rewardCode" src="/img/Wechat_appreciates.png" alt="打赏二维码">
        </div>
        
    </div>
</div>



</div>

        <footer class="footer">
    <div class="top">
        

        <p>
            
                <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            
            <span>This blog is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.</span>
        </p>
    </div>
    <div class="bottom">
        <!-- 统计网站用户访问量. 技术支持：不蒜子(http://busuanzi.ibruce.info/) ————> Mar 13,2019 -->
        <p>
            <font style='font-size: 12px;color:springgreen'>
                    <div align="center">
                        <!-- 安装脚本 -->
                        <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
                        <!-- 安装标签 -->
                        <span id="busuanzi_container_site_pv">
                            ◎用户总访问量 : <span id="busuanzi_value_site_pv"></span> 次 ~ &nbsp&nbsp
                        </span>
                        <span id="busuanzi_container_site_uv">
                            ◎总访客数(（づ￣3￣）づ╭❤～) : <span id="busuanzi_value_site_uv"></span>人 ~
                        </span>
                    </div>
                </font>
            </p>
            <!---------->
            <p>
                <font style='font-size: 10px'>
                    <span>黄宇辉 &copy; 2019 - 2020</span>
                    <span>
                        
                        Blog source <a href="https://github.com/YUbuntu0109/YUbuntu0109.github.io" target="_blank">Github</a> 
                        Power by <a href="http://hexo.io/" target="_blank">Hexo</a>
                        Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a>
                    </span>
                </font>
            </p>
        </div>
    </footer>
    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/&title=《Vue.js的生命周期》 — 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~&pic=https://yubuntu0109.github.io/img/my-portrait.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/&title=《Vue.js的生命周期》 — 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~&source=My Personal Website For Blog" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《Vue.js的生命周期》 — 欢迎参观小灰灰的网站哟 ヾ(◍°∇°◍)ﾉﾞ ~&url=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/&via=https://yubuntu0109.github.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="//api.qrserver.com/v1/create-qr-code/?data=https://yubuntu0109.github.io/2019/07/20/Vue-js的生命周期/" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/', SHARE: true, REWARD: true };


</script>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@latest/js/search.min.js" async></script>








<script>
(function() {
    var OriginTitile = document.title, titleTime;
    document.addEventListener('visibilitychange', function() {
        if (document.hidden) {
            document.title = 'Where are you going ?';
            clearTimeout(titleTime);
        } else {
            document.title = 'As long as you love me ~';
            titleTime = setTimeout(function() {
                document.title = OriginTitile;
            },2000);
        }
    });
})();
</script>



</body>
</html>
